﻿using Analyzer.Entities;
using Analyzer.Models;
using CsvHelper;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using OsmSharp.Routing.TSP;
using OsmSharp.Routing.TSP.Genetic;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Text.RegularExpressions;

namespace Analyzer.Tests
{
    [TestClass]
    public class ReportTest
    {
        [TestMethod]
        public void GenerateReport_Expect_No_Exceptions()
        {
            string projectDir = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);

            StringBuilder sb = new StringBuilder("[");
            using (StreamReader reader = new StreamReader(@"Assets\Braking\log_1.ilf"))
            {
                sb.Append(reader.ReadToEnd());
            }
            sb.Append("]");
            sb.Replace(",]", "]");

            ReportModel newReport = new ReportModel();

            List<ReportModel.SnapshotModel> snapshots = Newtonsoft.Json.JsonConvert.DeserializeObject<List<ReportModel.SnapshotModel>>(sb.ToString());

            foreach (ReportModel.SnapshotModel _snapshot in snapshots)
            {
                ReportModel.SnapshotModel snapshot = newReport.AddSnapshot();
                snapshot.Acceleration = _snapshot.Acceleration;
                snapshot.Heading = _snapshot.Heading;
                snapshot.Latitude = _snapshot.Latitude;
                snapshot.Longitude = _snapshot.Longitude;
                snapshot.Speed = _snapshot.Speed;
                snapshot.Throttle = _snapshot.Throttle;
                snapshot.VIN = _snapshot.VIN;
                snapshot.XAxis = _snapshot.XAxis;
                snapshot.YAxis = _snapshot.YAxis;
                snapshot.ZAxis = _snapshot.ZAxis;
            }

            try
            {
                newReport.Analyze();
                Debug.WriteLine("done");
            }
            catch (SystemException ex)
            {
                Assert.Fail("An unexpected exception occurred. " + ex);
            }
        }
    }
}
